package main

import (
	"fmt"

	ziamv1 "gitee.com/youkelike/ziam/zsdk/services/ziam/v1/authz"
	"github.com/ory/ladon"
)

func main() {
	// 1、通过传入秘钥拿到 client
	client, _ := ziamv1.NewClientWithSecret("SgU85emFNRKfI7Lh91smvjkRC2hw9c2Xe4LH", "jSZyJpgJk5x1Mr76TT0YUGtwvpbuHcK7")

	// 2、拿到请求结构，给请求结构赋值，每次请求数据都不一样
	req := ziamv1.NewAuthzRequest()
	// 请求体中的字段都是指针类型，方便判断字段是否被指定
	req.Resource = ziamv1.String("resources:articles:ladon-introduction")
	req.Action = ziamv1.String("delete")
	req.Subject = ziamv1.String("users:maria")
	ctx := ladon.Context(map[string]interface{}{"remoteIPAddress": "192.168.0.5"})
	req.Context = &ctx

	// 3、调用 client 的接口方法时传入构造的请求实例，获得返回对象实例
	resp, err := client.Authz(req)
	if err != nil {
		fmt.Println("err1", err)
		return
	}
	fmt.Printf("get response body: `%s`\n", resp.String())
	fmt.Printf("allowed: %v\n", resp.Allowed)
}
